-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log a warning for uncommitted changes on transaction exit #266
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #266 +/- ##
==========================================
+ Coverage 94.24% 94.32% +0.08%
==========================================
Files 5 5
Lines 382 388 +6
Branches 70 72 +2
==========================================
+ Hits 360 366 +6
Misses 13 13
Partials 9 9 ☔ View full report in Codecov by Sentry. |
src/lakefs_spec/transaction.py
Outdated
if any(True for _ in self._ephemeral_branch.uncommitted()): | ||
logger.warning( | ||
f"Transaction closed with uncommitted changes. {'Objects added but not committed are lost.' if self.delete != 'never' else ''}" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if any(True for _ in self._ephemeral_branch.uncommitted()): | |
logger.warning( | |
f"Transaction closed with uncommitted changes. {'Objects added but not committed are lost.' if self.delete != 'never' else ''}" | |
) | |
if any(self._ephemeral_branch.uncommitted()): | |
msg = f"Finished transaction {self._ephemeral_branch.id!r} contains uncommitted changes." | |
if self.delete != "never": | |
msg += " Objects added but not committed are lost." | |
warnings.warn(msg) |
Explanation: We always prefer a warning over a log, because that works even when the user does not set up logging. If the user needs logging, he can do import logging; logging.capturewarnings(True)
, if he wants to catch the warnings, he can do so with a warnings filter context manager or by redirecting stderr.
Bonus: We keep a clean separation between stdout and stderr.
3769e24
to
aae415c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
aae415c
to
c599118
Compare
Closes #264